package com.javabasic.algorithm.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiongmin
 * @version 0.0.1
 * @description Created by work on 2021/10/13 12:43 上午
 * @see
 */
public class FizzBuzz {

    /**
     * 暴力解法
     * 可优化：既是3的倍数又是5的倍数  那么既是15的倍数
     * @param n
     * @return
     */
    public List<String> fizzBuzz(int n) {
        List<String> result = new ArrayList<>(n);
        for (int i = 1; i <= n; i++) {
            if (i%3 != 0 && i%5 != 0) {
                result.add(String.valueOf(i));
            } else if (i%3 == 0 && i%5 == 0) {
                result.add("FizzBuzz");
            } else if (i%3 == 0) {
                result.add("Fizz");
            } else {
                result.add("Buzz");
            }
        }

        return result;
    }

    public List<String> fizzBuzz2(int n) {
        List<String> result = new ArrayList<>(n);
        for (int i = 1; i <= n; i++) {
            if (i%3 != 0 && i%5 != 0) {
                result.add(String.valueOf(i));
            } else if (i%15 == 0) {
                result.add("FizzBuzz");
            } else if (i%3 == 0) {
                result.add("Fizz");
            } else {
                result.add("Buzz");
            }
        }

        return result;
    }
}
